<?php
namespace app\admin\model;
use think\Model;
use think\Db;
/**
 * Created by PhpStorm.
 * User: 空房间
 * Date: 2018/2/17
 * Time: 14:20
 */
class Checks extends Model
{
    public function checks_list()
    {
        $info_list = Db::table('mzzs_checks')
            ->alias('c')
            ->field('c.id as cid,u.id as uid,c.title,u.username,c.hospital_id')
            ->join('__USER__ u','c.operator_id = u.id')
            ->select();
        return $info_list;
    }
    /**
     * 新增数据
     * @param $data  新增数组
     */
    public function save_info($data)
    {
        $this->startTrans();
        $add_info = $this->data($data)->save();
        if($add_info === false)
        {
            $this->rollback();
            return false;
        }
        $this->commit();
        return true;
    }
    /**
     * 根据ID查询数据
     */
    public function getInfoById($condition = array()){
           $where = array();
           if($condition)$where =  array_merge($condition,$where);
           $info = Db::table('mzzs_checks')
               ->where($where)
               ->find();
        return $info;
    }
    /**
     * 更新数据
     */
    public function update_info($condition='',$data)
    {
        $result = Db::table('mzzs_checks')->where('id',$condition)->update($data);
        if($result !== false)
        {
            return true;
        }else{
            return false;
        }
    }
    /**
     * 删除数据
     */
    public function del_info($condition=array()){
        $result = Db::table('mzzs_checks')->where('id',$condition)->delete();
       return  $result ? true:false;
    }
}